<template>
  <div>
    <h2>注册表单</h2>
    <input v-model="username" type="text" placeholder="用户名" />
    <input v-model="password" type="password" placeholder="密码" />
    <button @click="handleRegister">注册</button>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { useUserStore } from "../stores/userStore";

// 定义表单数据
const username = ref("");
const password = ref("");

// 获取用户存储实例
const userStore = useUserStore();

// 处理注册逻辑
const handleRegister = () => {
  if (username.value && password.value) {
    userStore.registerUser(username.value, password.value);
    // 注册成功后清空表单
    username.value = "";
    password.value = "";
  } else {
    console.log("用户名和密码不能为空");
  }
};
</script>